<!--<script src="http://server.chat:8080/socket.io/socket.io.js"></script>-->
<script src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
<script>
	//var socket = io.connect('http://server.chat:8080');
	var name = prompt('What\'s your name');
	$(function() {
		$('#submit').click(function() {
			var message = $('#message').val();
			$('#content').append(name + ': ' + message);
			var param = {
				'func': 'sendMessage',
				'sender': name,
				'message': message,
			};
			sendMessage(param);
		});
		
		//setInterval(getMessage, 1000);
		getMessage()
	});
	
	function sendMessage(data) {
		$.ajax({
			url: 'http://server.chat:8080/',
			type: 'POST',
			dataType: 'json',
			data: $.param(data),
		});
	}
	
	function getMessage() {
		var data = {
			'func': 'getMessage',
		};
		$.ajax({
			url: 'http://server.chat:8080/',
			type: 'POST',
			dataType: 'json',
			data: $.param(data),
		}).done(function(response) {
			$.each(response, function(i, v) {
				$('#content').append(v.sender + ': ' + v.message);
			});
			getMessage();
		});
	}
	
	
</script>

<input type="text" id="message"/>
<input type="button" id="submit" value="push"/>
<br/>
<div id="content"></div>